.class public final Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;
.super Ljava/lang/Object;
.source "SQLiteCookieStorage.java"

# interfaces
.implements Lcom/burstly/lib/network/beans/cookie/ICookieStorage;


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;
    }
.end annotation


# static fields
.field private static final LOG:Lcom/burstly/lib/util/LoggerExt; = null

.field private static final TAG:Ljava/lang/String; = "SQLiteCookieStorage"


# instance fields
.field private mCookieDatabase:Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;

.field private volatile mUsableState:Z


# direct methods
.method static constructor <clinit>()V
    .locals 1

    .prologue
    .line 48
    invoke-static {}, Lcom/burstly/lib/util/LoggerExt;->getInstance()Lcom/burstly/lib/util/LoggerExt;

    move-result-object v0

    sput-object v0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->LOG:Lcom/burstly/lib/util/LoggerExt;

    return-void
.end method

.method public constructor <init>(Landroid/content/Context;)V
    .locals 6
    .parameter "context"

    .prologue
    const/4 v5, 0x0

    .line 65
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 67
    :try_start_0
    new-instance v1, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;

    invoke-direct {v1, p1}, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;-><init>(Landroid/content/Context;)V

    iput-object v1, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->mCookieDatabase:Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;

    .line 68
    const/4 v1, 0x1

    iput-boolean v1, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->mUsableState:Z

    .line 69
    sget-object v1, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v2, "SQLiteCookieStorage"

    const-string v3, "Initialization completed."

    const/4 v4, 0x0

    new-array v4, v4, [Ljava/lang/Object;

    invoke-virtual {v1, v2, v3, v4}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
    :try_end_0
    .catch Ljava/lang/Throwable; {:try_start_0 .. :try_end_0} :catch_0

    .line 76
    :goto_0
    return-void

    .line 71
    :catch_0
    move-exception v0

    .line 72
    .local v0, exception:Ljava/lang/Throwable;
    sget-object v1, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v2, "SQLiteCookieStorage"

    const-string v3, "Exception during initialization sql database."

    new-array v4, v5, [Ljava/lang/Object;

    invoke-virtual {v1, v2, v3, v4}, Lcom/burstly/lib/util/LoggerExt;->logWarning(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 73
    sget-object v1, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v2, "SQLiteCookieStorage"

    invoke-virtual {v1, v2, v0}, Lcom/burstly/lib/util/LoggerExt;->logThrowable(Ljava/lang/String;Ljava/lang/Throwable;)V

    .line 74
    const/4 v1, 0x0

    iput-object v1, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->mCookieDatabase:Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;

    goto :goto_0
.end method

.method static synthetic access$000()Lcom/burstly/lib/util/LoggerExt;
    .locals 1

    .prologue
    .line 38
    sget-object v0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->LOG:Lcom/burstly/lib/util/LoggerExt;

    return-object v0
.end method


# virtual methods
.method public clear()V
    .locals 1

    .prologue
    .line 155
    iget-boolean v0, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->mUsableState:Z

    if-eqz v0, :cond_0

    .line 156
    iget-object v0, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->mCookieDatabase:Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;

    invoke-virtual {v0}, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;->beginTransaction()V

    .line 157
    iget-object v0, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->mCookieDatabase:Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;

    invoke-virtual {v0}, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;->deleteAll()V

    .line 158
    iget-object v0, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->mCookieDatabase:Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;

    invoke-virtual {v0}, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;->commit()V

    .line 160
    :cond_0
    return-void
.end method

.method public deleteCookie(Ljava/lang/String;)V
    .locals 1
    .parameter "cookieName"

    .prologue
    .line 144
    if-eqz p1, :cond_0

    iget-boolean v0, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->mUsableState:Z

    if-eqz v0, :cond_0

    .line 145
    iget-object v0, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->mCookieDatabase:Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;

    invoke-virtual {v0}, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;->beginTransaction()V

    .line 146
    iget-object v0, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->mCookieDatabase:Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;

    invoke-virtual {v0, p1}, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;->deleteCookie(Ljava/lang/String;)V

    .line 147
    iget-object v0, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->mCookieDatabase:Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;

    invoke-virtual {v0}, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;->commit()V

    .line 149
    :cond_0
    return-void
.end method

.method public getValidCookies()Ljava/util/Collection;
    .locals 14
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "()",
            "Ljava/util/Collection",
            "<",
            "Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;",
            ">;"
        }
    .end annotation

    .prologue
    .line 80
    iget-boolean v8, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->mUsableState:Z

    if-nez v8, :cond_1

    .line 81
    invoke-static {}, Ljava/util/Collections;->emptyList()Ljava/util/List;

    move-result-object v7

    .line 106
    :cond_0
    :goto_0
    return-object v7

    .line 84
    :cond_1
    iget-object v8, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->mCookieDatabase:Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;

    invoke-virtual {v8}, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;->getSavedCookies()Ljava/util/List;

    move-result-object v1

    .line 85
    .local v1, cookiesInDatabase:Ljava/util/List;,"Ljava/util/List<Lcom/burstly/lib/network/beans/cookie/CookieTO;>;"
    if-eqz v1, :cond_4

    invoke-interface {v1}, Ljava/util/List;->isEmpty()Z

    move-result v8

    if-nez v8, :cond_4

    .line 86
    new-instance v7, Ljava/util/ArrayList;

    invoke-direct {v7}, Ljava/util/ArrayList;-><init>()V

    .line 87
    .local v7, validCookies:Ljava/util/List;,"Ljava/util/List<Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;>;"
    invoke-static {}, Ljava/lang/System;->currentTimeMillis()J

    move-result-wide v2

    .line 88
    .local v2, currentTime:J
    const-wide/16 v4, 0x0

    .line 90
    .local v4, expirationTime:J
    iget-object v8, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->mCookieDatabase:Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;

    invoke-virtual {v8}, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;->beginTransaction()V

    .line 91
    invoke-interface {v1}, Ljava/util/List;->iterator()Ljava/util/Iterator;

    move-result-object v6

    .local v6, i$:Ljava/util/Iterator;
    :goto_1
    invoke-interface {v6}, Ljava/util/Iterator;->hasNext()Z

    move-result v8

    if-eqz v8, :cond_3

    invoke-interface {v6}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lcom/burstly/lib/network/beans/cookie/CookieTO;

    .line 92
    .local v0, cookie:Lcom/burstly/lib/network/beans/cookie/CookieTO;
    invoke-virtual {v0}, Lcom/burstly/lib/network/beans/cookie/CookieTO;->getExpirationTime()Ljava/lang/Long;

    move-result-object v8

    invoke-virtual {v8}, Ljava/lang/Long;->longValue()J

    move-result-wide v4

    .line 93
    cmp-long v8, v4, v2

    if-gez v8, :cond_2

    .line 94
    iget-object v8, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->mCookieDatabase:Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;

    invoke-virtual {v0}, Lcom/burstly/lib/network/beans/cookie/CookieTO;->getName()Ljava/lang/String;

    move-result-object v9

    invoke-virtual {v8, v9}, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;->deleteCookie(Ljava/lang/String;)V

    .line 95
    sget-object v8, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v9, "SQLiteCookieStorage"

    const-string v10, "Cookie expired: {0}. Expiration time: {1}"

    const/4 v11, 0x2

    new-array v11, v11, [Ljava/lang/Object;

    const/4 v12, 0x0

    aput-object v0, v11, v12

    const/4 v12, 0x1

    new-instance v13, Ljava/util/Date;

    invoke-direct {v13, v4, v5}, Ljava/util/Date;-><init>(J)V

    aput-object v13, v11, v12

    invoke-virtual {v8, v9, v10, v11}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    goto :goto_1

    .line 97
    :cond_2
    new-instance v9, Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;

    invoke-virtual {v0}, Lcom/burstly/lib/network/beans/cookie/CookieTO;->getCookieContent()Ljava/lang/String;

    move-result-object v8

    const-class v10, Lcom/burstly/lib/network/beans/cookie/CookieHolder;

    invoke-static {v8, v10}, Lcom/burstly/lib/util/Utils;->fromJson(Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Object;

    move-result-object v8

    check-cast v8, Lcom/burstly/lib/network/beans/cookie/CookieHolder;

    invoke-virtual {v0}, Lcom/burstly/lib/network/beans/cookie/CookieTO;->getExpirationTime()Ljava/lang/Long;

    move-result-object v10

    invoke-virtual {v10}, Ljava/lang/Long;->longValue()J

    move-result-wide v10

    invoke-direct {v9, v8, v10, v11}, Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;-><init>(Lcom/burstly/lib/network/beans/cookie/CookieHolder;J)V

    invoke-interface {v7, v9}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    goto :goto_1

    .line 101
    .end local v0           #cookie:Lcom/burstly/lib/network/beans/cookie/CookieTO;
    :cond_3
    iget-object v8, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->mCookieDatabase:Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;

    invoke-virtual {v8}, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;->commit()V

    .line 102
    invoke-interface {v7}, Ljava/util/List;->size()I

    move-result v8

    if-gtz v8, :cond_0

    .line 106
    .end local v2           #currentTime:J
    .end local v4           #expirationTime:J
    .end local v6           #i$:Ljava/util/Iterator;
    .end local v7           #validCookies:Ljava/util/List;,"Ljava/util/List<Lcom/burstly/lib/network/beans/cookie/CookieHolderWrapper;>;"
    :cond_4
    invoke-static {}, Ljava/util/Collections;->emptyList()Ljava/util/List;

    move-result-object v7

    goto/16 :goto_0
.end method

.method public processCookies(Ljava/util/Collection;)V
    .locals 13
    .parameter
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Ljava/util/Collection",
            "<",
            "Lcom/burstly/lib/network/beans/cookie/CookieHolder;",
            ">;)V"
        }
    .end annotation

    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/lang/Exception;
        }
    .end annotation

    .prologue
    .line 111
    .local p1, inputCookies:Ljava/util/Collection;,"Ljava/util/Collection<Lcom/burstly/lib/network/beans/cookie/CookieHolder;>;"
    if-nez p1, :cond_0

    .line 112
    new-instance v7, Ljava/lang/IllegalArgumentException;

    const-string v8, "Cannot process null-referenced list of cookies."

    invoke-direct {v7, v8}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V

    throw v7

    .line 114
    :cond_0
    iget-boolean v7, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->mUsableState:Z

    if-eqz v7, :cond_1

    invoke-interface {p1}, Ljava/util/Collection;->isEmpty()Z

    move-result v7

    if-eqz v7, :cond_2

    .line 136
    :cond_1
    :goto_0
    return-void

    .line 118
    :cond_2
    invoke-static {}, Ljava/lang/System;->currentTimeMillis()J

    move-result-wide v1

    .line 122
    .local v1, currentTime:J
    iget-object v7, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->mCookieDatabase:Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;

    invoke-virtual {v7}, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;->beginTransaction()V

    .line 123
    invoke-interface {p1}, Ljava/util/Collection;->iterator()Ljava/util/Iterator;

    move-result-object v6

    .local v6, i$:Ljava/util/Iterator;
    :cond_3
    :goto_1
    invoke-interface {v6}, Ljava/util/Iterator;->hasNext()Z

    move-result v7

    if-eqz v7, :cond_6

    invoke-interface {v6}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lcom/burstly/lib/network/beans/cookie/CookieHolder;

    .line 124
    .local v0, cookie:Lcom/burstly/lib/network/beans/cookie/CookieHolder;
    if-eqz v0, :cond_3

    .line 125
    iget-object v7, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->mCookieDatabase:Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;

    invoke-virtual {v0}, Lcom/burstly/lib/network/beans/cookie/CookieHolder;->getName()Ljava/lang/String;

    move-result-object v8

    invoke-virtual {v7, v8}, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;->exists(Ljava/lang/String;)Z

    move-result v3

    .line 126
    .local v3, exists:Z
    invoke-virtual {v0}, Lcom/burstly/lib/network/beans/cookie/CookieHolder;->getMaxage()Ljava/lang/Integer;

    move-result-object v7

    invoke-virtual {v7}, Ljava/lang/Integer;->intValue()I

    move-result v7

    int-to-long v7, v7

    const-wide/16 v9, 0x3e8

    mul-long/2addr v7, v9

    add-long v4, v1, v7

    .line 127
    .local v4, expirationTime:J
    iget-object v8, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->mCookieDatabase:Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;

    if-nez v3, :cond_4

    const/4 v7, 0x1

    :goto_2
    invoke-virtual {v8, v0, v7, v4, v5}, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;->saveOrUpdateCookie(Lcom/burstly/lib/network/beans/cookie/CookieHolder;ZJ)V

    .line 128
    if-eqz v3, :cond_5

    .line 129
    sget-object v7, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v8, "SQLiteCookieStorage"

    const-string v9, "Cookie updated: {0}. Expiration time: {1}"

    const/4 v10, 0x2

    new-array v10, v10, [Ljava/lang/Object;

    const/4 v11, 0x0

    aput-object v0, v10, v11

    const/4 v11, 0x1

    new-instance v12, Ljava/util/Date;

    invoke-direct {v12, v4, v5}, Ljava/util/Date;-><init>(J)V

    aput-object v12, v10, v11

    invoke-virtual {v7, v8, v9, v10}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    goto :goto_1

    .line 127
    :cond_4
    const/4 v7, 0x0

    goto :goto_2

    .line 131
    :cond_5
    sget-object v7, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v8, "SQLiteCookieStorage"

    const-string v9, "New cookie added: {0}. Expiration time: {1}"

    const/4 v10, 0x2

    new-array v10, v10, [Ljava/lang/Object;

    const/4 v11, 0x0

    aput-object v0, v10, v11

    const/4 v11, 0x1

    new-instance v12, Ljava/util/Date;

    invoke-direct {v12, v4, v5}, Ljava/util/Date;-><init>(J)V

    aput-object v12, v10, v11

    invoke-virtual {v7, v8, v9, v10}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    goto :goto_1

    .line 135
    .end local v0           #cookie:Lcom/burstly/lib/network/beans/cookie/CookieHolder;
    .end local v3           #exists:Z
    .end local v4           #expirationTime:J
    :cond_6
    iget-object v7, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->mCookieDatabase:Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;

    invoke-virtual {v7}, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;->commit()V

    goto :goto_0
.end method
